﻿using System.Web;
using log4net;

namespace Karma.Framework.Core.Services.Invoker.Handler
{
    public class SessionHandler : IHttpHandler
    {
        private static ILog LOG = LogManager.GetLogger(typeof(SessionHandler).Name);

        public void ProcessRequest(HttpContext context)
        {
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Renewing session...");
            }
            //var principal = HttpContext.Current.User;
            //var authCookie = FormsAuthentication.GetAuthCookie(principal.Identity.Name, false);

            //if (authCookie == null)
            //{
            //    if (LOG.IsDebugEnabled)
            //    {
            //        LOG.Debug("There is no cookie.");
            //    }
            //    return;
            //}
            //var ticket = FormsAuthentication.Decrypt(authCookie.Value);
            //if (ticket == null)
            //{
            //    if (LOG.IsDebugEnabled)
            //    {
            //        LOG.Debug("Ticket is null.");
            //    }
            //    return;
            //}
            //FormsAuthentication.RenewTicketIfOld(ticket);
            //if (LOG.IsDebugEnabled)
            //{
            //    LOG.Debug("Session renewed.");
            //}
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
